3c089d8722494fe67be6809f11c7f7dd38173233,passport/src/main/java/com/continuuity/passport/http/handlers/AccountHandler.java,AccountHandler,createAccount,#String#,293

Before Change


      emailId = jsonObject.get("email_id") == null ? null : jsonObject.get("email_id").getAsString();

      if ((emailId == null)) {
        return Response.status(Response.Status.BAD_REQUEST)
          .entity(Utils.getJson("FAILED", "Email id is missing")).build();
      } else {
        Account account = dataManagementService.registerAccount(new Account("", "", "", emailId));
        requestSuccess();
        return Response.ok(account.toString()).build();
      }
    } catch (AccountAlreadyExistsException e) {
      //If the account already exists - return the existing account so that the caller can take appropriate action
      Account account = dataManagementService.getAccount(emailId);
      requestFailed(); // Request failed
      LOG.error("Account creation failed endpoint: %s %s", "POST /passport/v1/account", "Account already exists");
      return Response.status(Response.Status.CONFLICT)
        .entity(Utils.getJsonError("FAILED", account))
        .build();
    } catch (JsonParseException e) {
      requestFailed();
      LOG.error(String.format("Bad request while processing endpoint: %s %s",
        "POST /passport/v1/account", e.getMessage()));
      return Response.status(Response.Status.BAD_REQUEST)
        .entity(Utils.getJson("FAILED", String.format("Json parse exception. %s", e.getMessage())))
        .build();
    } catch (Exception e) {
      requestFailed(); // Request failed
      LOG.error(String.format("Internal server error while processing endpoint: %s %s",
        "POST /passport/v1/account", e.getMessage()));
      return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
        .entity(Utils.getJson("FAILED", String.format("Account Creation Failed. %s", e)))
        .build();
    }
  }

After Change


      emailId = jsonObject.get("email_id") == null ? null : jsonObject.get("email_id").getAsString();

      if ((emailId == null)) {
        responder.sendString(HttpResponseStatus.BAD_REQUEST,
                             Utils.getJson("FAILED", "Email id is missing"));
      } else {
        Account account = dataManagementService.registerAccount(new Account("", "", "", emailId));
        requestSuccess();
        responder.sendString(HttpResponseStatus.OK, account.toString());
      }
    } catch (AccountAlreadyExistsException e) {
      //If the account already exists - return the existing account so that the caller can take appropriate action
      Account account = dataManagementService.getAccount(emailId);
      requestFailed(); // Request failed
      LOG.error("Account creation failed endpoint: %s %s", "POST /passport/v1/account", "Account already exists");
      responder.sendString(HttpResponseStatus.CONFLICT, Utils.getJsonError("FAILED", account));
    } catch (JsonParseException e) {
      requestFailed();
      LOG.error(String.format("Bad request while processing endpoint: %s %s",
        "POST /passport/v1/account", e.getMessage()));
      responder.sendString(HttpResponseStatus.BAD_REQUEST,
                           Utils.getJson("FAILED", String.format("Json parse exception. %s", e.getMessage())));
    } catch (Exception e) {
      requestFailed(); // Request failed
      LOG.error(String.format("Internal server error while processing endpoint: %s %s",
        "POST /passport/v1/account", e.getMessage()));
      responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR,
                           Utils.getJson("FAILED", String.format("Account Creation Failed. %s", e)));
    }
  }